import { View } from "../../../../mvc/core/View";
import { ObjCreate } from "../../common/ObjCreate";
import { GScrollPane } from "../../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { Cache } from "../../../cache/Cache";
import { SPetExploreRecord } from "../../../../../Message/Public/SPetExploreRecord";
import { PetExploreConfig } from "../../../resource/PetExploreConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { DateParser } from "../../../../common/tools/DateParser";
import { EPetExploreRecordType } from "../../../../../Message/Public/EPetExploreRecordType";
import { Language } from "../../../../../extend/language/Language";
import { SReward } from "../../../../../Message/Public/SReward";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
//class PetExploreRecordsPanel
    
    export  class PetExploreRecordsPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 250, 280, this);
            this._contentTxt = ObjCreate.createTextField("", 5, 5, 225, 270, this);
            this._contentTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._contentTxt.multiline = true;
            this._contentTxt.wordWrap = true;
            this._contentPane = new GScrollPane();
            this._contentPane.styleName = "GScrollPane";
            this._contentPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._contentPane.verticalScrollPolicy = ScrollPolicy.ON;
            this._contentPane.width = 235;
            this._contentPane.height = 270;
            this._contentPane.source = this._contentTxt;
            this._contentPane.move(12, 5);
            this.addChild(this._contentPane);
            return;
        }

        /* internal  */updateByContent(arg1: string): void
        {
            this._contentTxt.htmlText = "<textFormat leading=\'5\'>" + arg1 + "</textFormat>";
            this._contentPane.update();
            return;
        }

        public /* override */ set visible(arg1: Boolean)
        {
            super.visible = arg1;
            if (arg1) 
            {
                this.updateByContent(this.getLogString(Cache.instance.petExplore.records));
            }
            return;
        }

        /* internal  */getLogString(arg1: Array<any>): string
        {
            var loc2=null;
            var loc3=null;
            var loc4=false;
            var loc6=null;
            var loc1="";
            var loc5=(arg1.length - 1);
            while (loc5 >= 0) 
            {
                loc2 = arg1[loc5] as SPetExploreRecord;
                loc4 = loc2.extend > 0;
                loc3 = PetExploreConfig.instance.getExploreConfigByLevel(loc2.level);
                loc6 = (loc6 = "") + HTMLUtil.addColor("●" + DateParser.parse(loc2.recordDt, "[MM-dd hh: mm]"), "#e4ff00");
                if (loc2.type.value() != EPetExploreRecordType._EPetExploreRecordResult) 
                {
                    loc6 = loc6 + (Language.getStringByParam(54489, loc2.extend) + this.getItemsNameStr(loc2.getItems));
                    if (loc2.lossItems.length > 0) 
                    {
                        loc6 = loc6 + (Language.getString(54490) + this.getItemsNameStr(loc2.lossItems));
                    }
                }
                else if (loc4) 
                {
                    loc6 = loc6 + (Language.getStringByParam(54486, loc3.name) + this.getItemsNameStr(loc2.getItems));
                    if (loc2.lossItems.length > 0) 
                    {
                        loc6 = loc6 + (Language.getString(54487) + this.getItemsNameStr(loc2.lossItems));
                    }
                }
                else 
                {
                    loc6 = loc6 + Language.getStringByParam(54488, loc3.name);
                }
                loc1 = loc1 + (loc6 + "\n");
                --loc5;
            }
            loc1 = HTMLUtil.addColor(loc1, "#B1efff");
            return loc1;
        }

        /* internal  */getItemsNameStr(arg1: Array<any>): string
        {
            var loc2=null;
            var loc3=null;
            var loc1="";
            var loc4="";
            var loc5=0;
            while (loc5 < arg1.length) 
            {
                loc2 = arg1[loc5] as SReward;
                loc3 = new ItemData(loc2.code);
                if (loc5 != (arg1.length - 1)) 
                {
                    loc4 = "，";
                }
                else 
                {
                    loc4 = "。";
                }
                loc1 = loc1 + (ItemsUtil.getItemName(loc3) + "*" + loc2.num + loc4);
                ++loc5;
            }
            return loc1;
        }

        /* internal */ /* var */_contentPane: GScrollPane;

        /* internal */ /* var */_contentTxt: Object /* flash.text.TextField */;
    }
